package com.example.entity;

import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;

import org.springframework.stereotype.Component;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class Course {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private Integer id;
	private String name;
	@OneToMany(cascade=CascadeType.ALL,mappedBy="course")
	@JsonIgnore
	private Set<Grade> grade;
	

    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(name="maj_cou",joinColumns=@JoinColumn(name="course_id",referencedColumnName="id"),
    inverseJoinColumns=@JoinColumn(name="student_id",referencedColumnName="id"))
    @JsonIgnore
    private Set<Major> major = new HashSet<>();
    @ManyToMany(cascade=CascadeType.ALL)
    @JoinTable(name="course_tea",joinColumns=@JoinColumn(name="course_id",referencedColumnName="id"),
    inverseJoinColumns=@JoinColumn(name="teacher_id",referencedColumnName="id"))
    @JsonIgnore//为了防止栈溢出,防止set之间相互调用
	private Set<Teacher> teacher = new HashSet<>();

	public Course() {
		
	}
    
	public Course(String name, Set<Major> major, Set<Teacher> teacher) {
		super();
		this.name = name;
		this.major = major;
		this.teacher = teacher;
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public Set<Grade> getGrade() {
		return grade;
	}

	public void setGrade(Set<Grade> grade) {
		this.grade = grade;
	}

	public void setMajor(Set<Major> major) {
		this.major = major;
	}

	public void setName(String name) {
		this.name = name;
	}

	@JsonIgnore
	public Set<Major> getMajor() {
		return major;
	}

	public void setStudent(Set<Major> major) {
		this.major = major;
	}

	public Set<Teacher> getTeacher() {
		return teacher;
	}

	public void setTeacher(Set<Teacher> teacher) {
		this.teacher = teacher;
	}
}
